package com.ruoyi.web.controller.detect;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.detect.domain.Residential;
import com.ruoyi.detect.service.IResidentialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 无Controller
 *
 * @author ruoyi
 * @date 2023-01-10
 */
@RestController
@RequestMapping("/detect/residential")
public class ResidentialController extends BaseController {
    @Autowired
    private IResidentialService residentialService;

    /**
     * 查询无列表
     */
    @PreAuthorize("@ss.hasPermi('detect:residential:list')")
    @GetMapping("/list")
    public TableDataInfo list(Residential residential) {
        startPage();
        List<Residential> list = residentialService.selectResidentialList(residential);
        return getDataTable(list);
    }

    /**
     * 导出无列表
     */
    @PreAuthorize("@ss.hasPermi('detect:residential:export')")
    @Log(title = "无", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Residential residential) {
        List<Residential> list = residentialService.selectResidentialList(residential);
        ExcelUtil<Residential> util = new ExcelUtil<Residential>(Residential.class);
        util.exportExcel(response, list, "无数据");
    }

    /**
     * 获取无详细信息
     */
    @PreAuthorize("@ss.hasPermi('detect:residential:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(residentialService.selectResidentialById(id));
    }

    /**
     * 新增无
     */
    @PreAuthorize("@ss.hasPermi('detect:residential:add')")
    @Log(title = "无", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Residential residential) {
        return toAjax(residentialService.insertResidential(residential));
    }

    /**
     * 修改无
     */
    @PreAuthorize("@ss.hasPermi('detect:residential:edit')")
    @Log(title = "无", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Residential residential) {
        return toAjax(residentialService.updateResidential(residential));
    }

    /**
     * 删除无
     */
    @PreAuthorize("@ss.hasPermi('detect:residential:remove')")
    @Log(title = "无", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(residentialService.deleteResidentialByIds(ids));
    }


    @GetMapping("/lists")
    public AjaxResult getList() {
        return residentialService.getList();
    }

}
